import dayjs from 'dayjs';
import * as calendarApi from '@/service/assist/calendar'

interface SForm {
  nowTime?: string,
  startTime?: string,
  endTime?: string,
  lastMonth?: string,
  nextMonth?: string,
}

export const useCalendarSearch = async (calendarType: string, dateValue: string) => {
  const form: SForm = {};
  if(calendarType == 'day') {
    form.nowTime = dayjs(dateValue).format('YYYY-MM-DD').toString()
  }
  else if(calendarType == 'week') {
    form.startTime = dayjs(dateValue).startOf('week').format('YYYY-MM-DD').toString()
    form.endTime = dayjs(dateValue).endOf('week').format('YYYY-MM-DD').toString()
  }
  else if(calendarType == 'month') {
    form.lastMonth = dayjs(dateValue).subtract(1, 'month').format('YYYY-MM-DD').toString()
    form.nextMonth = dayjs(dateValue).add(1, 'month').format('YYYY-MM-DD').toString()
  }

  try {
    const res = await calendarApi.selectSchedule(form);
    return res.code == 0 ? res.data : []
  } catch (error) {}

  return []
}